############## 类的工具方法
class Animal(object):
    def run(self):
        print('Animal is running...')


class Dog(Animal):
    pass;

class Cat(Animal):
    def run(self):
        print('Cat is running...');


dog = Dog();
dog2 = Dog();
cat = Cat();

print('#===========================type函数=====================');

tp = type('str');
print(tp); #out: <class 'str'>

a = 123;
tp = type(a);
print(tp); #out: <class 'int'>

tp = type(None);
print(tp); #out: <class 'NoneType'>

tp = type(abs); #内建函数：abs()
print(tp);#out: <class 'builtin_function_or_method'>

tp = type(dog);
print(tp);#out: <class '__main__.Dog'>

tp = type(Dog);
print(tp);#out: <class 'type'>

a = 123;
if type(a) == int:
    print(a, "type is int");
if type(dog) == type(dog2):
    print("dog's type == dog2's type")

'''
自定义函数的type：types.FunctionType
内建函数的type：  types.BuiltinFunctionType
Lamda表达式的type：types.LambdaType
type((x for x in range(10)))==types.GeneratorType
'''


print('#===========================isinstance函数=====================');
#判断对象类型
r = isinstance(dog, Animal);
print(r);
#判断基本类型：
isinstance('a', str)
isinstance(123, int)
isinstance(b'a', bytes)
#判断一个变量是否是某些类型中的一种
isinstance([1, 2, 3], (list, tuple))  #判断[1,2,3]是否list或tuple
isinstance((1, 2, 3), (list, tuple))

print('#===========================dir函数=====================');


print('#===========================type函数=====================');
print('#===========================type函数=====================');
print('#===========================type函数=====================');
print('#===========================type函数=====================');
print('#===========================type函数=====================');
print('#===========================type函数=====================');
